import ajax from '../utils/ajax'
import '../auth';
import '../../scss/test.scss';
import $ from '../jquery-3.4.1.min.js';
$("#main-left ul li:not(:nth-of-type(1))").hide();
let sjtype = false;
let sftype = false;
let wytype = false;
let zltype = false;
let wltype = false;
$("#main-left").on('click', 'li', function () {//左侧点击ul
    let text = $(this).text();
    if (text != '数据中心' && text != '收费管理' && text != '物业服务' && text != '租赁管理' && text != '物料管理') {
        $("#main-left ul li:not(:nth-of-type(1))").removeAttr('class');
        $(this).attr('class', 'main-left-li-active');
        $("#main-left-sy").removeAttr('class');
    }
    switch (text) {
        case '首页':
            $("#main-left-sy").attr('class', 'main-left-li-active');
            $("#main-left ul li:not(:nth-of-type(1))").hide();
            location.href = '../../index.html';
            break;
        case '数据中心':
            if (sjtype == false) {
                sjtype = true;
                $(this).parents('ul').children().show();
            } else {
                sjtype = false;
                $(".sj li:not(:nth-of-type(1))").hide();
            };
            break;
        case '收费管理':
            if (sftype == false) {
                sftype = true;
                $(this).parents('ul').children().show();
            } else {
                sftype = false;
                $(".sf li:not(:nth-of-type(1))").hide();
            };
            break;
        case '物业服务':
            if (wytype == false) {
                wytype = true;
                $(this).parents('ul').children().show();
            } else {
                wytype = false;
                $(".wy li:not(:nth-of-type(1))").hide();
            };
            break;
        case '租赁管理':
            if (zltype == false) {
                zltype = true;
                $(this).parents('ul').children().show();
            } else {
                zltype = false;
                $(".zl li:not(:nth-of-type(1))").hide();
            };
            break;
        case '物料管理':
            if (wltype == false) {
                wltype = true;
                $(this).parents('ul').children().show();
            } else {
                wltype = false;
                $(".wl li:not(:nth-of-type(1))").hide();
            };
            break;
    }
    if (text == '收银台' || text == '抄表录入' || text == '未交账单' || text == '缴费通知' || text == '已交账单' || text == '预存款管理' || text == '收费设置') {
        location.href = `../../chargeManagement.html?${text}`;
    }
    else if (text == '小区管理' || text == '楼宇管理' || text == '车位管理' || text == '业主管理' || text == '租客管理' || text == '访客管理' || text == '广告位管理' || text == '车辆管理') {
        location.href = `../../dataCenter.html?${text}`;
    }
    else if (text == '客户管理' || text == '车位租赁' || text == '广告位租赁' || text == '房屋租赁' || text == '合同管理') {
        location.href = `../../lease.html?${text}`;
    }
    else if (text == '供应商管理' || text == '仓库管理' || text == '物料清单' || text == '采购入库' || text == '领用出库' || text == '维修领退材' || text == '库存查询') {
        location.href = `../../material.html?${text}`;
    }
})
// 个人信息下拉菜单
let xialacaidan = false;
$("#xialacaidan").hide();
$("#hd-chose").on('mousemove', '#hd-select', function () {
    $("#xialacaidan").slideDown(500);
    xialacaidan = true;
})
$("#hd-right").on('mouseleave', '#xialacaidan,#hd-touxiang,#hd-news', function () {
    if (xialacaidan == true) {
        $("#xialacaidan").slideUp(500);
        xialacaidan = false;
    }
})
$("#xialacaidan").on('click', 'li', function () {
    const text = $(this).text();
    switch (text) {
        case '个人中心':
            location.href = '../../pim.html';
            break;
        case '修改密码':
            $("#nav-change-password").show();
            break;
        case '退出登录':
            localStorage.clear();
            location.href = '../../login.html';
            break;
    }
})
$("#logo").on("click", 'img', function () {
    location.href = '../../index.html';
})
$("#nav-change-password").on('click', '#dingwei-x ,#quxiao', function () {
    $("#nav-change-password").hide();
})
var regpass = /^[A-Z][[a-zA-Z0-9]{5,15}/;//验证密码
let passmsg;
$("#nav-change-password").on('blur', '#xm', function () {//新密码
    var nowxm = $('#xm').val();
    if (!regpass.test(nowxm)) {
        $("#xm").css("border", "1px solid red");
        $("#password-msg").text("请输入正确的密码格式-/^[A-Z][[a-zA-Z0-9]{5,15}/");
        passmsg = $("#password-msg").text();
    } else {
        $("#xm").css("border", "1px solid #ccc");
        $("#password-msg").text("");
        passmsg = $("#password-msg").text();
    }
})
ajax({//获取解析的token的password
    url: '/pjw-user/getUserInfo',
    type: 'POST',
    success(res) {
        if (res.code == 200) {
            var password = res.data.password;
            $("#nav-change-password").on('click', '#navok', function () {//修改密码
                const ym = $("#ym").val();
                const xm = $("#xm").val();
                const xxm = $("#xxm").val();
                console.log(ym, xm, xxm, password);
                if (ym == password && xm == xxm) {
                    ajax({
                        url: '/pjw-user/getPass',
                        type: 'POST',
                        data: {
                            password: xxm
                        },
                        success(res) {
                            if (res.code == 200) {
                                alert('成功');
                                localStorage.clear();
                                location.href = '../../login.html';
                            } else {
                                alert('失败');
                            }
                        }
                    })
                } else {
                    alert('请输入正确的密码');
                }

            })
        }
    }
})



$("#main-left").on('click', '.go-yw', function () {
    var result = confirm('是否跳转到新页面!!!!');
    if (result == true) {
        location.href = 'http://192.168.13.6:7000/list.html';
    }
})